<!--<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <title>门店管理后台</title>
    <link rel="stylesheet" href="./plugins/layui/css/layui.css" media="all">
    <script src="./static/js/jquery-1.9.1.min.js"></script>
</head>
<body>
<div class="admin-main">
    <blockquote class="layui-elem-quote">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <div class="layui-input-inline">
                    <input type="text" id="selectValue" lay-verify="required" placeholder="客户姓名，电话" autocomplete="off"
                           class="layui-input">
                </div>
                <button class="layui-btn" type="button" id="selectButton">搜索</button>
            </div>
        </form>
        <span><a href="shop_customer_manager_page_info">显示所有客户</a></span>
    </blockquote>
    <fieldset class="layui-elem-field">
        <legend>客户列表</legend>
        <div class="layui-field-box layui-form">
            <table class="layui-table admin-table" id="t_customerInfo">

            </table>
        </div>
    </fieldset>
    <div class="admin-table-page">
        <div id="paged" class="page">
        </div>
    </div>
</div>
<script src="./plugins/layui/layui.js"></script>
<script type="text/javascript">
  $(document).ready(function () {
    //ajax请求后台数据
    getShopCustomerManagePageInfo();
    //点击搜索时 搜索数据
    $("#selectButton").click(function () {
      getShopCustomerManagePageInfo();
      currentPageAllAppoint = 1; //当点击搜索的时候，应该回到第一页
      toPage();//然后进行分页的初始化

    })
    toPage();
  });
  //分页参数设置 这些全局变量关系到分页的功能
  var startAllAppoint = 0;//开始页数
  var limitAllAppoint = 10;//每页显示数据条数
  var currentPageAllAppoint = 1;//当前页数
  var dataLength = 0;//数据总条数
  //ajax请求后台数据   "http://47.96.37.107:8332/manager/stagingtype/list"
  function getShopCustomerManagePageInfo() {
    var a = null;
    var startTime = null;
    var arr = {
      token: '55f634776fe75a3f862f19757b1db129',
      pageNum: currentPageAllAppoint,
      pageSize: limitAllAppoint,
      resName: null,
      type: a,
      resUrl: startTime,
    }
    $.ajax({
      type: "POST",
//          async: false,
      url: "http://192.168.100.211:8080/loan/back/resources/resourcesManagePage",
      dataType: 'JSON',
      data: arr,
      success: function (data) {
//            data = eval("(" + data + ")");
        if (data.code == 0) {
          var list = data.result.data.resultList;
          console.log(list, 'dsuhu')
          getShopCustomesInfo(list);
          currentPageAllAppoint = data.result.data.currentPage;//当前页数(后台返回)
          dataLength = data.result.data.totalRecord;//数据总条数
        }
      }
    });
  }
  function getShopCustomesInfo(data) {
    var s = "<tr><th>id</th><th>名称</th><th>节点</th><th>父节点</th><th>类型</th><th>说明</th><th>状态</th><th>操作</th></tr>";
    $.each(data, function (v, o) {   //$.each()便利json对象
      //v: 下标    o: 内容
      var nodes = '',
          myTypes = '',
          user = '';
      if (o.parentName == null) {
        nodes = '主节点'
      } else {
        nodes = o.parentName
      }
      if (o.type == 1) {
        myTypes = '菜单'
      } else {
        myTypes = '接口'
      }
      if (o.status == 1) {
        user = '可用'
      } else {
        user = '禁用'
      }
      s += '<tr><td>' + o.id + '</td>';
      s += '<td>' + o.resName + '</td>';
      s += '<td>' + o.resUrl + '</td>';
      s += '<td>' + nodes + '</td>';
      s += '<td>' + myTypes + '</td>';
      s += '<td>' + o.resRemark + '</td>';
      s += '<td>' + user + '</td>';
    });
    if (data.length > 0) {
      $("#t_customerInfo").html(s);
    } else {
      $("#page1").hide();
      $("#t_customerInfo").html("<br/><span style='width:10%;height:30px;display:block;margin:0 auto;'>暂无数据</span>");
    }
  }

  function toPage() {
    layui.use(['form', 'laypage', 'layedit', 'layer', 'laydate'], function () {
      var form = layui.form,
          layer = layui.layer,
          layedit = layui.layedit,
          laydate = layui.laydate,
          laypage = layui.laypage;
      render = layui.render;

      var nums = 10;
      //调用分页
      laypage.render({
        elem: 'paged'  //指向存放分页的容器，值可以是ID、DOM对象
        //1. elem: 'id' 注意：这里不能加 # 号
        //2. elem: document.getElementById('id')
        , count: dataLength //这个是后台返回的数据的总条数
        , limit: limitAllAppoint   //每页显示的数据的条数,layui会根据count，limit进行分页的计算
        , curr: currentPageAllAppoint  //起始页。一般用于刷新类型的跳页以及HASH跳页
        , jump: function (obj, first) {
          //obj:（当前分页的所有选项值） first:（是否首次，一般用于初始加载的判断）
          currentPageAllAppoint = obj.curr;
          startAllAppoint = (obj.curr - 1) * obj.limit;
          if (!first) { //一定要加此判断，否则初始时会无限刷新
            getShopCustomerManagePageInfo();//一定要把翻页的ajax请求放到这里，不然会请求两次。
//                location.href = '?page='+obj.curr;
          }
        }
      });
    });
  };

</script>
</body>
</html>